#pragma once

#include <string>
#include <ostream>

#include "topdbs_base_session.hpp"
#include "informix_connection.hpp"

class ITConnection;
class ITDBInfo;
class ITQuery;
class ITCursor;
class ITStatement;
class ITSet;
class ITValue;
class ITRow;
class ITString;

namespace topdbs
{
	class informix_session 
		: public topdbs_base_session
	{	
	protected:
		informix_connection* m_pConnection;	
		std::string m_isamtx;
		ITStatement* m_pStmt;
		ITCursor* m_pCursor;
		ITQuery*  m_pStream;
	public:	
		informix_session();
		informix_session(informix_connection* pConnection);
		virtual ~informix_session();

		//! reset the current command all info.
		virtual void Reset() override;
		//! Validates and prepares the current command for execution.
		virtual int  Prepare() override;
		//! Executes the current command.
		virtual int  Execute() override; 
		virtual int  Execute(const char* sSQL,...) override; 	
		virtual int  ExecuteV(const string& sSQL,va_list vaList) override;
		virtual int  ExecuteFetch(const string& sSQL) override;
		virtual bool FetchNext() override;
		virtual bool FetchCursorNext(uint16_t nFetchSize = TOPDBS_DEFAULT_FETCH_SIZE) override;
		//! Binding the command parameter specified by its position
		virtual int  BindParams(const uint16_t paramno,const DBSValue& value) override;
		virtual int  BindParams(const uint16_t params_no,const string& value) override;
		virtual int  BindParams(const uint16_t params_no,const int     value) override;
		virtual int  BindParams(const uint16_t params_no,const long    value) override;
		virtual int  BindParams(const uint16_t params_no,const float   value) override;
		virtual int  BindParams(const uint16_t params_no,const double  value) override;

	private:
		int ExecuteUpdate(const std::string& sSQL);
		int ExecuteQuery(const std::string& sSQL);
		int ExecuteQuery_Row(const std::string& sSQL);
		int SetITValue(ITConnection* pITConn,ITValue* pITValue,const string& colval );
		int GetITValue(ITConnection* pITConn,ITValue* pITValue,string& colval);
	};
}